// DlgOpenCom.cpp : implementation file
//

#include "stdafx.h"
#include "RFUsbDemo.h"
#include "DlgOpenCom.h"

#include "umfh.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



/////////////////////////////////////////////////////////////////////////////
// CDlgOpenCom dialog


CDlgOpenCom::CDlgOpenCom(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgOpenCom::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgOpenCom)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgOpenCom::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgOpenCom)
	DDX_Control(pDX, IDC_COMBO1, m_Comb_fport);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgOpenCom, CDialog)
	//{{AFX_MSG_MAP(CDlgOpenCom)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgOpenCom message handlers

void CDlgOpenCom::OnButton1() 
{
	// TODO: Add your control notification handler code here
	icdev=-1;
	icdev=fw_init(GetPort(),38400);

	if( -1 !=icdev)
	{
		int fret=fw_beep(icdev,10);
		AfxMessageBox(L"OK get device handle");
	}
	else AfxMessageBox(L"Not get device handle");
}
int CDlgOpenCom::GetPort()
{
	//
//USB1
//USB2
//USB3
//COM1
//COM2
//COM3
//COM4
//COM5
//COM6
	int port;
	switch(m_Comb_fport.GetCurSel())
	{
	case 0://USB1
		port=100;
		break;
	case 1://USB2
		port=101;
		break;
	case 2://USB3
		port=102;
		break;
	case 3://COM1
		port=0;
		break;
	case 4://COM2
		port=1;
		break;
	case 5://COM3
		port=2;
		break;
	case 6://COM4
		port=3;
		break;
	case 7://COM5
		port=4;
		break;
	case 8://COM6
		port=5;
		break;
	default:
		port=20;//no this port
		break;
	}

	return port;

}

BOOL CDlgOpenCom::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	m_Comb_fport.SetCurSel(0);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
